.class public Lcom/glympse/platform/common/SearchJob;
.super Lcom/glympse/platform/common/HttpJob;
.source "SearchJob.java"


# instance fields
.field m_listSearchResults:Lcom/glympse/platform/GVector$SearchResults;

.field m_oSearchResultsListener:Lcom/glympse/platform/common/SearchResultsListener;


# direct methods
.method public constructor <init>(Ljava/lang/String;Lcom/glympse/platform/common/LocPoint;Lcom/glympse/platform/common/SearchResultsListener;)V
    .locals 4
    .parameter "strSearch"
    .parameter "oLocPoint"
    .parameter "oSearchResultsListener"

    .prologue
    .line 25
    invoke-direct {p0}, Lcom/glympse/platform/common/HttpJob;-><init>()V

    .line 21
    const/4 v1, 0x0

    iput-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_oSearchResultsListener:Lcom/glympse/platform/common/SearchResultsListener;

    .line 22
    new-instance v1, Lcom/glympse/platform/GVector$SearchResults;

    invoke-direct {v1}, Lcom/glympse/platform/GVector$SearchResults;-><init>()V

    iput-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_listSearchResults:Lcom/glympse/platform/GVector$SearchResults;

    .line 30
    iput-object p3, p0, Lcom/glympse/platform/common/SearchJob;->m_oSearchResultsListener:Lcom/glympse/platform/common/SearchResultsListener;

    .line 31
    const/4 v1, 0x1

    iput-boolean v1, p0, Lcom/glympse/platform/common/SearchJob;->m_fCompleteOnMainThread:Z

    .line 34
    if-nez p2, :cond_0

    .line 36
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v1

    iget-object v1, v1, Lcom/glympse/platform/Platform;->m_oLocManager:Lcom/glympse/platform/LocManager;

    iget-object p2, v1, Lcom/glympse/platform/LocManager;->m_oLastLocPoint:Lcom/glympse/platform/common/LocPoint;

    .line 40
    :cond_0
    const-string v1, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&rsz=large"

    iput-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_strUrl:Ljava/lang/String;

    .line 43
    invoke-static {}, Lcom/glympse/platform/Platform;->GetLanguageCode()Ljava/lang/String;

    move-result-object v0

    .line 44
    .local v0, strLanguage:Ljava/lang/String;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_1

    .line 46
    iget-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_strUrl:Ljava/lang/String;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-static {v1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-direct {v2, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v1, "&hl="

    invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-static {v0}, Lcom/glympse/platform/Platform;->UrlEncode(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    iput-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_strUrl:Ljava/lang/String;

    .line 50
    :cond_1
    if-eqz p2, :cond_2

    invoke-virtual {p2}, Lcom/glympse/platform/common/LocPoint;->HasLocation()Z

    move-result v1

    if-eqz v1, :cond_2

    .line 52
    iget-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_strUrl:Ljava/lang/String;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-static {v1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-direct {v2, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v1, "&sll="

    invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    iget-wide v2, p2, Lcom/glympse/platform/common/LocPoint;->m_dLatitude:D

    invoke-virtual {v1, v2, v3}, Ljava/lang/StringBuilder;->append(D)Ljava/lang/StringBuilder;

    move-result-object v1

    const-string v2, ","

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    iget-wide v2, p2, Lcom/glympse/platform/common/LocPoint;->m_dLongitude:D

    invoke-virtual {v1, v2, v3}, Ljava/lang/StringBuilder;->append(D)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    iput-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_strUrl:Ljava/lang/String;

    .line 56
    :cond_2
    iget-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_strUrl:Ljava/lang/String;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-static {v1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-direct {v2, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v1, "&q="

    invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-static {p1}, Lcom/glympse/platform/Platform;->UrlEncode(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    iput-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_strUrl:Ljava/lang/String;

    .line 58
    new-instance v1, Ljava/lang/StringBuilder;

    const-string v2, "Google Local Search: "

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    iget-object v2, p0, Lcom/glympse/platform/common/SearchJob;->m_strUrl:Ljava/lang/String;

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 59
    return-void
.end method


# virtual methods
.method public OnComplete(Lcom/glympse/platform/common/JobQueue;)V
    .locals 2
    .parameter "oJobQueue"

    .prologue
    .line 160
    iget-object v0, p0, Lcom/glympse/platform/common/SearchJob;->m_oSearchResultsListener:Lcom/glympse/platform/common/SearchResultsListener;

    iget-object v1, p0, Lcom/glympse/platform/common/SearchJob;->m_listSearchResults:Lcom/glympse/platform/GVector$SearchResults;

    invoke-interface {v0, v1}, Lcom/glympse/platform/common/SearchResultsListener;->Complete(Lcom/glympse/platform/GVector$SearchResults;)V

    .line 161
    return-void
.end method

.method public ProcessResponse()V
    .locals 9

    .prologue
    const/4 v8, 0x0

    const-wide/16 v6, 0x0

    .line 64
    iget-object v4, p0, Lcom/glympse/platform/common/SearchJob;->m_abResponse:[B

    if-nez v4, :cond_1

    .line 155
    :cond_0
    :goto_0
    return-void

    .line 69
    :cond_1
    new-instance v4, Lcom/glympse/platform/common/CharArrayPointer;

    iget-object v5, p0, Lcom/glympse/platform/common/SearchJob;->m_abResponse:[B

    invoke-direct {v4, v5}, Lcom/glympse/platform/common/CharArrayPointer;-><init>([B)V

    invoke-static {v4}, Lcom/glympse/platform/common/Helpers;->ParseJSON(Lcom/glympse/platform/common/CharArrayPointer;)Lcom/glympse/platform/GVector$NameValueNodes;

    move-result-object v1

    .line 70
    .local v1, listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    if-eqz v1, :cond_0

    .line 75
    const/4 v3, 0x0

    .line 78
    .local v3, oSearchResult:Lcom/glympse/platform/common/SearchResult;
    invoke-virtual {v1}, Lcom/glympse/platform/GVector$NameValueNodes;->elements()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, iter:Ljava/util/Enumeration;
    :cond_2
    :goto_1
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v4

    if-nez v4, :cond_3

    .line 151
    if-eqz v3, :cond_0

    .line 153
    invoke-virtual {v3, v8}, Lcom/glympse/platform/common/SearchResult;->Complete(Z)Z

    goto :goto_0

    .line 80
    :cond_3
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/glympse/platform/common/NameValueNode;

    .line 83
    .local v2, oNodeCur:Lcom/glympse/platform/common/NameValueNode;
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "GsearchResultClass"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_5

    .line 86
    if-eqz v3, :cond_4

    .line 88
    invoke-virtual {v3, v8}, Lcom/glympse/platform/common/SearchResult;->Complete(Z)Z

    .line 92
    :cond_4
    new-instance v3, Lcom/glympse/platform/common/SearchResult;

    .end local v3           #oSearchResult:Lcom/glympse/platform/common/SearchResult;
    invoke-direct {v3}, Lcom/glympse/platform/common/SearchResult;-><init>()V

    .line 95
    .restart local v3       #oSearchResult:Lcom/glympse/platform/common/SearchResult;
    iget-object v4, p0, Lcom/glympse/platform/common/SearchJob;->m_listSearchResults:Lcom/glympse/platform/GVector$SearchResults;

    invoke-virtual {v4, v3}, Lcom/glympse/platform/GVector$SearchResults;->addElement(Ljava/lang/Object;)V

    goto :goto_1

    .line 100
    :cond_5
    if-eqz v3, :cond_2

    .line 106
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "lat"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_6

    .line 108
    iget-wide v4, v3, Lcom/glympse/platform/common/SearchResult;->m_dLatitude:D

    cmpl-double v4, v6, v4

    if-nez v4, :cond_2

    .line 110
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    invoke-static {v4}, Lcom/glympse/platform/common/Helpers;->ParseDouble(Ljava/lang/String;)D

    move-result-wide v4

    iput-wide v4, v3, Lcom/glympse/platform/common/SearchResult;->m_dLatitude:D

    goto :goto_1

    .line 113
    :cond_6
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "lng"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_7

    .line 115
    iget-wide v4, v3, Lcom/glympse/platform/common/SearchResult;->m_dLongitude:D

    cmpl-double v4, v6, v4

    if-nez v4, :cond_2

    .line 117
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    invoke-static {v4}, Lcom/glympse/platform/common/Helpers;->ParseDouble(Ljava/lang/String;)D

    move-result-wide v4

    iput-wide v4, v3, Lcom/glympse/platform/common/SearchResult;->m_dLongitude:D

    goto :goto_1

    .line 120
    :cond_7
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "titleNoFormatting"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_8

    .line 122
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    iput-object v4, v3, Lcom/glympse/platform/common/SearchResult;->m_strTitle:Ljava/lang/String;

    goto :goto_1

    .line 124
    :cond_8
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "streetAddress"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_9

    .line 126
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    iput-object v4, v3, Lcom/glympse/platform/common/SearchResult;->m_strStreet:Ljava/lang/String;

    goto :goto_1

    .line 128
    :cond_9
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "city"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_a

    .line 130
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    iput-object v4, v3, Lcom/glympse/platform/common/SearchResult;->m_strCity:Ljava/lang/String;

    goto/16 :goto_1

    .line 132
    :cond_a
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "region"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_b

    .line 134
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    iput-object v4, v3, Lcom/glympse/platform/common/SearchResult;->m_strState:Ljava/lang/String;

    goto/16 :goto_1

    .line 136
    :cond_b
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "country"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_c

    .line 138
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    iput-object v4, v3, Lcom/glympse/platform/common/SearchResult;->m_strCountry:Ljava/lang/String;

    goto/16 :goto_1

    .line 140
    :cond_c
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "postalCode"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_d

    .line 142
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    iput-object v4, v3, Lcom/glympse/platform/common/SearchResult;->m_strPostalCode:Ljava/lang/String;

    goto/16 :goto_1

    .line 144
    :cond_d
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strName:Ljava/lang/String;

    const-string v5, "number"

    invoke-virtual {v4, v5}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_2

    .line 146
    iget-object v4, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    iput-object v4, v3, Lcom/glympse/platform/common/SearchResult;->m_strPhoneNumber:Ljava/lang/String;

    goto/16 :goto_1
.end method
